package com.cxz.study.infra.inbound.controller;

import com.cxz.study.definition.OrderServiceDefinition;
import com.cxz.study.application.order.web.OrderVO;
import com.cxz.study.application.order.web.useCase.CreateOrderUseCase;
import com.cxz.study.common.Result;
import com.cxz.study.domain.order.command.CreateOrderCommand;
import com.cxz.study.dto.CreateOrderReq;
import com.cxz.study.dto.CreateOrderResp;
import com.cxz.study.infra.inbound.controller.mapper.OrderApiMapperStruct;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @className: CreateOrderController
 * @author: ocxz1
 * @date: 2025/6/15 下午3:49
 * @Version: 1.0
 * @description: ddd-struct3
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/order")
public class CreateOrderApiController implements OrderServiceDefinition {
    private final OrderApiMapperStruct orderMapper;
    private final CreateOrderUseCase createOrderUseCase;

    @PostMapping("/createOrder")
    public Result<CreateOrderResp> createOrder(@RequestBody CreateOrderReq req) {
        CreateOrderCommand createOrderCommand = orderMapper.toCreateOrderCommand(req);
        OrderVO orderVO = createOrderUseCase.execute(createOrderCommand);
        CreateOrderResp createOrderResp = orderMapper.toCreateOrderResp(orderVO);
        return Result.success(createOrderResp);
    }
}
